package com.kfm.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/requestA")
public class RequestAServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("requestA service ...");
        // 在request域中设置一个内容 param1 key params value
        req.setAttribute("msg", "hello kfm");
        // 获取request域中的内容 getAttribute(key)
        System.out.println(req.getAttribute("msg"));
        // 请求转发
        req.getRequestDispatcher("/requestB").forward(req, resp);
        System.out.println("requestA service done");
        System.out.println(req.getAttribute("msg"));
    }
}
